﻿using System;
using System.Collections.Generic;
using Quartz;

namespace WeChartWorkRobot.Service.Jobs
{
    [Serializable]
    public class CronTrigger : TriggerBase
    {
        public string CornExpression { get; }
        private DateTime? _startAt;

        public CronTrigger(string cornExpression)
        {
            CornExpression = cornExpression;
        }

        public CronTrigger StartAt(DateTime dateTime)
        {
            _startAt = dateTime;
            return this;
        }


        protected internal override ITrigger GetQuartzTrigger()
        {
            var builder = TriggerBuilder.Create();
            return builder
                .WithCronSchedule(this.CornExpression)
                .Build();
        }

        public override DateTimeOffset? GetNextRunTime()
        {
            return GetQuartzTrigger().GetFireTimeAfter(DateTimeOffset.Now);
        }
    }
}
